﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEngine;

// Token: 0x0200017C RID: 380
public class CommonLib
{
	// Token: 0x060009CE RID: 2510 RVA: 0x000397FC File Offset: 0x000379FC
	public static List<string> GetAssetBundleNameListFromPath(string path, bool subdirCheck = false)
	{
		List<string> result = new List<string>();
		if (!AssetBundleCheck.IsSimulation)
		{
			string path2 = AssetBundleManager.BaseDownloadingURL + path;
			if (subdirCheck)
			{
				List<string> list = new List<string>();
				CommonLib.GetAllFiles(path2, "*.unity3d", list);
				result = (from s in list
				select s.Replace(AssetBundleManager.BaseDownloadingURL, string.Empty)).ToList<string>();
			}
			else
			{
				if (!Directory.Exists(path2))
				{
					return result;
				}
				result = (from s in Directory.GetFiles(path2, "*.unity3d")
				select s.Replace(AssetBundleManager.BaseDownloadingURL, string.Empty)).ToList<string>();
			}
		}
		return result;
	}

	// Token: 0x060009CF RID: 2511 RVA: 0x000398B4 File Offset: 0x00037AB4
	public static List<string> GetAssetBundleNameListFromPath(string path, string searchPattern, bool subdirCheck = false)
	{
		List<string> result = new List<string>();
		if (!AssetBundleCheck.IsSimulation)
		{
			string path2 = AssetBundleManager.BaseDownloadingURL + path;
			if (subdirCheck)
			{
				List<string> list = new List<string>();
				CommonLib.GetAllFiles(path2, searchPattern, list);
				result = (from s in list
				select s.Replace(AssetBundleManager.BaseDownloadingURL, string.Empty)).ToList<string>();
			}
			else
			{
				if (!Directory.Exists(path2))
				{
					return result;
				}
				result = (from s in Directory.GetFiles(path2, searchPattern)
				select s.Replace(AssetBundleManager.BaseDownloadingURL, string.Empty)).ToList<string>();
			}
		}
		return result;
	}

	// Token: 0x060009D0 RID: 2512 RVA: 0x00039964 File Offset: 0x00037B64
	public static void GetAllFiles(string path, string searchPattern, List<string> lst)
	{
		if (!Directory.Exists(path))
		{
			return;
		}
		lst.AddRange(Directory.GetFiles(path, searchPattern));
		string[] directories = Directory.GetDirectories(path);
		for (int i = 0; i < directories.Length; i++)
		{
			CommonLib.GetAllFiles(directories[i], searchPattern, lst);
		}
	}

	// Token: 0x060009D1 RID: 2513 RVA: 0x000399B0 File Offset: 0x00037BB0
	public static string GetUUID()
	{
		string text = Application.dataPath;
		text = Path.GetDirectoryName(text);
		string path = text + "/UserData/save/netUID.dat";
		if (File.Exists(path))
		{
			using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read))
			{
				using (BinaryReader binaryReader = new BinaryReader(fileStream))
				{
					return binaryReader.ReadString();
				}
			}
		}
		return string.Empty;
	}

	// Token: 0x060009D2 RID: 2514 RVA: 0x00039A40 File Offset: 0x00037C40
	public static T LoadAsset<T>(string assetBundleName, string assetName, bool clone = false, string manifestName = "") where T : UnityEngine.Object
	{
		if (AssetBundleCheck.IsSimulation)
		{
			manifestName = string.Empty;
		}
		if (!AssetBundleCheck.IsFile(assetBundleName, assetName))
		{
			string text = "読み込みエラー\r\nassetBundleName：" + assetBundleName + "\tassetName：" + assetName;
			return (T)((object)null);
		}
		AssetBundleLoadAssetOperation assetBundleLoadAssetOperation = AssetBundleManager.LoadAsset(assetBundleName, assetName, typeof(T), (!manifestName.IsNullOrEmpty()) ? manifestName : null);
		if (assetBundleLoadAssetOperation.IsEmpty())
		{
			string text2 = "読み込みエラー\r\nassetName：" + assetName;
			return (T)((object)null);
		}
		T t = assetBundleLoadAssetOperation.GetAsset<T>();
		if (null != t && clone)
		{
			T t2 = UnityEngine.Object.Instantiate<T>(t);
			t2.name = t.name;
			t = t2;
		}
		return t;
	}

	// Token: 0x060009D3 RID: 2515 RVA: 0x00039B0C File Offset: 0x00037D0C
	public static T LoadForceAsset<T>(string assetBundleName, string assetName, bool clone = false, string manifestName = "") where T : UnityEngine.Object
	{
		if (AssetBundleCheck.IsSimulation)
		{
			manifestName = string.Empty;
		}
		AssetBundleLoadAssetOperation assetBundleLoadAssetOperation = AssetBundleManager.LoadAsset(assetBundleName, assetName, typeof(T), (!manifestName.IsNullOrEmpty()) ? manifestName : null);
		if (assetBundleLoadAssetOperation.IsEmpty())
		{
			string text = "読み込みエラー\r\nassetName：" + assetName;
			return (T)((object)null);
		}
		T t = assetBundleLoadAssetOperation.GetAsset<T>();
		if (null != t && clone)
		{
			T t2 = UnityEngine.Object.Instantiate<T>(t);
			t2.name = t.name;
			t = t2;
		}
		return t;
	}
}
